package com.mxf.code.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.code.fegin.ProviderClient;
import com.mxf.code.service.OrderServie;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.concurrent.atomic.AtomicInteger;

@RestController
@Slf4j
@RequestMapping("/order")
public class ConsumerController {

    @Autowired
    private OrderServie orderServie;

    public static final AtomicInteger atomicInteger = new AtomicInteger();

    @Resource
    private ProviderClient providerClient;

    @GetMapping("/hi/{id}")
    public String hi(@PathVariable("id") int id) {
        return providerClient.hi(id);
    }

    @SentinelResource("hot")
    @GetMapping("{orderid}")
    public String hot(@PathVariable("orderid")String orderid) {
        System.out.println(orderid);
        return orderid;
    }

    @GetMapping("/query")
    public String queryOrder() {
        orderServie.queryGoodsDetail();
        return atomicInteger.addAndGet(1) + "";
    }

    @GetMapping("/save")
    public String save() {
        orderServie.queryGoodsDetail();
        return atomicInteger.addAndGet(1) + "";
    }

    @GetMapping("/order/update")
    public String updateOrder() {
        return "更新操作";
    }
}

